using System;
using System.Reflection;
using NUnit.Framework;
using ValidationFramework.Reflection;

namespace ValidationFramework.Tests.Reflection
{

	public class RuleCollectionTest
	{
		[IncludeMember]
		public string Property
		{
			get;
			set;
		}

		readonly static RuntimeTypeHandle runtimeTypeHandle = typeof(RuleCollectionTest).TypeHandle;
		readonly static PropertyInfo propertyInfo = typeof(RuleCollectionTest).GetProperty("Property");
		readonly static  PropertyDescriptor propertyDescriptor;
		static RuleCollectionTest()
		{

            var getMethodInfo = propertyInfo.GetGetMethod(true);
            propertyDescriptor = new PropertyDescriptor(new TypeDescriptor(runtimeTypeHandle), propertyInfo, getMethodInfo);
		}
		public static RuleCollection GetRuleCollection()
		{
			return new RuleCollection(propertyDescriptor);
		}

		[TestFixture]
		public class Constructor
		{
			[Test]
			public void Simple()
			{
				var ruleCollection = GetRuleCollection();
				Assert.AreSame(propertyDescriptor, ruleCollection.InfoDescriptor);
			}

		}

		[TestFixture]
		public class SetItem
		{
			[Test]
			[ExpectedException(typeof(ArgumentNullException))]
			public void ExceptionNullItem()
			{
				var ruleCollection = GetRuleCollection();
				ruleCollection.Add(null, null);
			}

		}
	}
}